﻿using System;
using System.Collections;
using System.Collections.Generic;
using PureMVC.Interfaces;
using UnityEngine;

/// <summary>
/// PureMVC 核心类 Facade
/// 只需要创建一个即可
/// 
/// 负责完成proxy,mediator,command的初始化工作
/// 获取也均通过facade
/// 
/// 
/// 重写virtual方法 
/// 
/// 执行顺序：
/// Model->Controller->View->Facade的顺序
/// 重写Facade一定要调用base.InitializeFacade()
/// 
/// </summary>
public class MyFacade : PureMVC.Patterns.Facade
{

    /// <summary>
    /// 静态初始化 
    /// </summary>
    static MyFacade()
    {
        m_instance = new MyFacade();
    }

    /// <summary>
    /// 获取单例
    /// </summary>
    /// <returns></returns>
    public static MyFacade GetInstance()
    {
        return m_instance as MyFacade;
    }

    /// <summary>
    /// 启动MVC
    /// </summary>
    public void Launch()
    {
        //通过command命令启动游戏
        //启动主面板
        SendNotification(MsgID.START_UP);
        //启动商城
        SendNotification(MsgID.LOAD_SHOP);
        //启动背包
        SendNotification(MsgID.LOAD_BAG);
    }

    /// <summary>
    /// 初始化Controller，完成Notification和Command的映射
    /// </summary>
    protected override void InitializeController()
    {
        base.InitializeController();
        //注册Command
        RegisterCommand(MsgID.START_UP, typeof(StartUpCommand));
        RegisterCommand(MsgID.LOAD_SHOP, typeof(ShopCommand));
        RegisterCommand(MsgID.CREATE_SHOP_CELL, typeof(CreateShopCellCommand));
        RegisterCommand(MsgID.LOAD_BAG,typeof(BagCommand));
    }

    /// <summary>
    /// 初台化View,Initializes the view.
    /// View在Model和Controll之后运行
    /// UI的创建我放到Command中执行
    /// </summary>
    protected override void InitializeView()
    {
        base.InitializeView();
    }

    protected override void InitializeFacade()
    {
        base.InitializeFacade();
    }

    /// <summary>
    /// 初始化Model 数据模型  Proxy
    /// </summary>
    protected override void InitializeModel()
    {
        base.InitializeModel();
        //也可以放在Command中
        RegisterProxy(new PlayerDataProxy(PlayerDataProxy.NAME));
        RegisterProxy(new ShopProxy(ShopProxy.NAME));
        RegisterProxy(new BagProxy(BagProxy.NAME));
    }

}